package com.qingtian.example.web.service.impl;

import com.qingtian.example.web.dao.PeopleDao;
import com.qingtian.example.web.entity.People;
import com.qingtian.example.web.service.PeopleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author qingtian
 * @Description
 * @Date Created in 2018/3/15
 */
@Service("peopleService")
public class PeopleServiceImpl implements PeopleService{

    @Autowired
    private PeopleDao dao;

    public List<People> listAll(int offset, int limit) {
        return dao.listAll(offset,limit);
    }

    public People getById(long id) {
        return dao.getPeople(id);
    }

    @Transactional(rollbackFor = Exception.class)
    public People update(People entity) {
        dao.updatePeople(entity);
        return dao.getPeople(entity.getId());
    }

    @Transactional(rollbackFor = Exception.class)
    public People deleteById(long id) {
        People entity = dao.getPeople(id);
        dao.deletePeople(id);
        return entity;
    }

    @Transactional(rollbackFor = Exception.class)
    public People add(People entity) {
        dao.insertPeople(entity);
        return dao.getPeople(entity.getId());
    }
}
